package edu.stu.cs.software.family.base.domain;

import java.io.Serializable;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
 * All entity classes inherit from this base class of BaseEntity
 * @author Administrator
 *
 * @param <LG> PK long of id
 */
@MappedSuperclass
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
@Access(value = AccessType.FIELD)
public class BaseEntity<LG extends Serializable> extends BaseDomain{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3520098902018682371L;
	
	
	@Column(name = "ENTITY_NAME")
	protected String entityName;
	
	@Column(name = "DELETED")
	protected Boolean deleted;
	
	
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	protected LG id;
	
	@Version
	@Access(AccessType.FIELD)
	private long version;
	
	public LG getId() {
		return id;
	}

	public void setId(LG id) {
		this.id = id;
	}
	
	public Boolean getDeleted() {
		return deleted;
	}

	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}

	
	
	public String getEntityName() {
		return entityName;
	}

	public void setEntityName(String entityName) {
		this.entityName = entityName;
	}

	@Override
	public boolean equals(Object obj) {
		if (null != obj) {
			if (obj instanceof BaseEntity) {
				@SuppressWarnings("unchecked")
				BaseEntity<LG> domain =  (BaseEntity<LG>) obj;
				if (this.id == domain.id) {
					return true;
				}
			}
		}
		return false;
	}
	@Override
	public int hashCode() {
		
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public String toString() {
		
		return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);         
	}

}
